package com.solace.selenium.config;

import cn.hutool.crypto.CryptoException;
import com.solace.selenium.entity.JsonResult;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

@ControllerAdvice
@ResponseBody
public class GlobalExceptionHandler {
    /**
     * 作者 CG
     * 时间 2020/6/29 11:15
     * 注释 参数异常
     */
    @ExceptionHandler(ServiceException.class)
    public JsonResult serviceExceptionHandler(ServiceException ex) {
        return new JsonResult(ex, JsonResult.ERROR);
    }

    @ExceptionHandler(IllegalArgumentException.class)
    public JsonResult illegalArgumentExceptionHandler(IllegalArgumentException ex) {
//        ex.printStackTrace();
        return new JsonResult(ex, JsonResult.ERROR);
    }
    @ExceptionHandler(Exception.class)
    public JsonResult exceptionHandler(Exception ex) {
        ex.printStackTrace();
        return new JsonResult(JsonResult.ERROR,"未知系统错误!");
    }
    @ExceptionHandler(CryptoException.class)
    public JsonResult cryptoExceptionHandler(CryptoException ex) {
        return new JsonResult(JsonResult.ERROR,"授权码错误!");
    }
}